package game;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import java.util.ArrayList;

import client.ClientInternals;
/**
 * Permet de cliquer sur plusieurs cases d'un coup
 * @author Julien roch
 * @version 1
 */
public class BigClick extends EmptyCell implements MagicObject{

	/**
	 * pour la serialization
	 */
	private static final long serialVersionUID = -4102662639112330475L;
	private String player;
	/**
	 * Clique de 3x3 (bonus)
	 * @param point La position
	 * @param nbMinesAround Nombre de mines aux allentours
	 */
	public BigClick(Point point, int nbMinesAround) {
		super(point, nbMinesAround);
	}
	

	@Override
	public void visit(ServersideGame g, String player) {
		this.player = player;
	}

	@Override
	public Point[] makeSpecialAction(ServersideGame g, String player) {
		// on joue les 9 cases (3x3)...
		Dimension dimension = g.getDimension();
		ArrayList<Point> pts = new ArrayList<Point>();
		for(int i=Math.max(0, point.x-1);i<=Math.min(dimension.width-1, point.x+1);i++){
			for(int j=Math.max(0, point.y-1);j<=Math.min(dimension.height-1, point.y+1);j++){
				pts.add(new Point(i,j));
			}
		}
		return pts.toArray(new Point[pts.size()]);
	}

	@Override
	public void draw(Graphics g, Dimension d, ImageObserver observer) {
		super.draw(g, d, observer);
		Image i = Toolkit.getDefaultToolkit().getImage (this.getClass().getResource("/img/bigclick.png"));
		g.drawImage(i,0,0,d.width,d.height,observer);
	}
	@Override
	public void drawButton(Graphics g, Dimension d, ImageObserver observer) {
		Color c = g.getColor();
		g.setColor(Color.BLUE);
		g.fillRoundRect(0, 0, d.width, d.height,15,15);
		Image i = Toolkit.getDefaultToolkit().getImage (this.getClass().getResource("/img/bigclick.png"));
		g.drawImage(i,0,0,d.width,d.height,observer);
		i = Toolkit.getDefaultToolkit().getImage (this.getClass().getResource("/img/shadow.png"));
		g.drawImage(i,0,0,d.width,d.height,observer);
		g.setColor(c);
	}

	@Override
	public void HandleClientInternals(ClientInternals internals) {
		if(internals.getUserName().equals(player)){
			internals.putObject(this);
		}
	}

	
}
